package com.ssy.lingxi.after.sale.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 售后换货发货类型
 * @author 伍将
 * @date 2020/9/18
 * @version 2.0.0
 */
public enum ReplaceDeliveryGoodsTypeEnum {

    /**
     * 所有
     */
    ALL(0, "所有","",""),
    /**
     * 退货
     */
    RETURN_GOODS(1, "退货","退货发货单","退货收货单"),
    /**
     * 换货
     */
    REPLACE_GOODS(2, "换货","换货收货单","换货发货单");

    private final Integer code;
    private final String message;
    private final String buyerOrderName;
    private final String venderOrderName;

    ReplaceDeliveryGoodsTypeEnum(Integer code, String message,String buyerOrderName,String venderOrderName) {
        this.code = code;
        this.message = message;
        this.buyerOrderName=buyerOrderName;
        this.venderOrderName=venderOrderName;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public String getBuyerOrderName() {
        return LanguageHolder.getName(this.getDeclaringClass().getSimpleName().concat(".buyerOrderName.").concat(this.getCode().toString()));
    }

    public String getVenderOrderName() {
        return LanguageHolder.getName(this.getDeclaringClass().getSimpleName().concat(".venderOrderName.").concat(this.getCode().toString()));
    }

    public static ReplaceDeliveryGoodsTypeEnum findByCode(Integer code) {
        return Arrays.stream(ReplaceDeliveryGoodsTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    public static String getOrderTypeName(Integer code, boolean isSupplier){
        ReplaceDeliveryGoodsTypeEnum typeEnum = findByCode(code);
        if(typeEnum!=null){
            return isSupplier?typeEnum.getVenderOrderName():typeEnum.getBuyerOrderName();
        }
        return null;
    }
}
